package org.thinkinbunny.financial.data;

import java.util.UUID;

import org.thinkinbunny.financial.activity.MyActivity;
import org.thinkinbunny.financial.util.Log;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.telephony.TelephonyManager;

public class UpdateVerHelper {
	public static String getVerMisc(MyActivity myActivity) {

		try {
			PackageManager packageManager = myActivity.getPackageManager();
			// getPackageName()是你当前类的包名，0代表是获取版本信息
			PackageInfo packInfo = packageManager.getPackageInfo(
					myActivity.getPackageName(), 0);
			String version = "ver=" + packInfo.versionName;
			final TelephonyManager tm = (TelephonyManager) myActivity
					.getBaseContext().getSystemService(
							Context.TELEPHONY_SERVICE);

			final String tmDevice, tmSerial, tmPhone, androidId;

			tmDevice = "" + tm.getDeviceId();

			tmSerial = "" + tm.getSimSerialNumber();

			androidId = ""
					+ android.provider.Settings.Secure.getString(
							myActivity.getContentResolver(),
							android.provider.Settings.Secure.ANDROID_ID);

			UUID deviceUuid = new UUID(androidId.hashCode(),
					((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());

			String uniqueId = deviceUuid.toString();
			version += "&uuid=" + uniqueId;
			Log.d("debug", "uuid=" + uniqueId);

			return version;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			Log.i("UpdateVerHelper", "error exception");
			return null;
		}

	}
	public static String getVersion(MyActivity myActivity) {

		try {
			PackageManager packageManager = myActivity.getPackageManager();
			// getPackageName()是你当前类的包名，0代表是获取版本信息
			PackageInfo packInfo = packageManager.getPackageInfo(
					myActivity.getPackageName(), 0);
			String version = packInfo.versionName;


			return version;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			Log.i("UpdateVerHelper", "error exception");
			return null;
		}

	}
	// public static String getVerMisc(MyActivity myActivity) {
	//
	// try {
	// PackageManager packageManager = myActivity.getPackageManager();
	// // getPackageName()是你当前类的包名，0代表是获取版本信息
	// PackageInfo packInfo = packageManager.getPackageInfo(
	// myActivity.getPackageName(), 0);
	// String version = "ver=" + packInfo.versionName;
	// final TelephonyManager tm = (TelephonyManager) myActivity
	// .getBaseContext().getSystemService(
	// Context.TELEPHONY_SERVICE);
	//
	// final String tmDevice, tmSerial, tmPhone, androidId;
	//
	// tmDevice = "" + tm.getDeviceId();
	//
	// tmSerial = "" + tm.getSimSerialNumber();
	//
	// androidId = ""
	// + android.provider.Settings.Secure.getString(
	// myActivity.getContentResolver(),
	// android.provider.Settings.Secure.ANDROID_ID);
	//
	// UUID deviceUuid = new UUID(androidId.hashCode(),
	// ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
	//
	// String uniqueId = deviceUuid.toString();
	// version += "&uuid=" + uniqueId;
	// Log.d("debug", "uuid=" + uniqueId);
	//
	// return version;
	// } catch (Exception e) {
	// // TODO: handle exception
	// e.printStackTrace();
	// Log.i("UpdateVerHelper", "error exception");
	// return null;
	// }
	//
	// }

}
